package com.example.neusoft.yuejian.Base;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.example.neusoft.yuejian.Util.IsInternet;

public abstract class BaseFragment extends Fragment{
    public View view=null;

    public Context context;

    public abstract int getLayoutFile();

    abstract public void initView();

    abstract public void initEvent();

    abstract public void initData();

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(getLayoutFile(), container, false);
        context = getActivity();
        initView();
        initEvent();
        if (!IsInternet.isNetworkAvalible(getActivity())) {
            showToast("当前网络不可用，请检查网络设置");
        } else {
            initData();
        }
        return view;
    }

    public void showToast(String msg) {
        Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
    }
}
